#!/usr/bin/env bash
set -e

TAG="$1"

if [ ! -e arch.tar.gz ]; then
    curl -o arch.tar.gz -L https://mirrors.edge.kernel.org/archlinux/iso/latest/archlinux-bootstrap-$(date +%Y.%m).01-x86_64.tar.gz
fi

# Remove the trailing "/root.x86_64" from the base image.
if [ ! -e root.tar.gz ]; then
    rm -rf root.x86_64
    tar xpzf arch.tar.gz
    pushd root.x86_64
    tar -czpf ../root.tar.gz *
    popd
    rm -rf root.x86_64
fi

docker build --squash -t godarch/arch .
docker tag godarch/arch godarch/arch:$TAG
